#pragma once
#include<Windows.h>
void rc4_init(unsigned char* s, unsigned char* key, unsigned long Len)
{
	Sleep(0);
	int i = 0, j = 0, k[256] = { 0 };
	unsigned char tmp = 0;
	for (i = 0; i < 256; i++)
	{
		Sleep(0);
		s[i] = i;
		k[i] = key[i % Len];
	}
	for (i = 0; i < 256; i++)
	{
		j = (j + s[i] + k[i]) % 256;
		tmp = s[i];
		s[i] = s[j];
		s[j] = tmp;
	}
	Sleep(0);
}

void rc4_crypt(unsigned char* s, unsigned char* Data, unsigned long Len)
{
	Sleep(0);
	int x = 0, y = 0, t = 0;
	unsigned char tmp;
	unsigned long i;
	for (i = 0; i < Len; i++)
	{
		x = (x + 1) % 256;
		y = (y + s[x]) % 256;
		tmp = s[x];
		s[x] = s[y];
		s[y] = tmp;
		t = (s[x] + s[y]) % 256;
		Data[i] ^= s[t];
	}
	Sleep(0);
}